package com.centriole.service.workflow.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.HashMap;

/**
 * Project: xyc
 * Create by:      刘锐
 * Phone:  18782973813
 * Email：rui.liu@hirebigdata.cn
 * Date：     2015/12/17
 * Description：
 * <p/>
 * Function：
 * 1.
 */
public class ContextUtils implements ApplicationContextAware {

    private static HashMap<String,Object> beanList = new HashMap();
    private static ApplicationContext context;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    private static ApplicationContext getContext() {
        return context;
    }

    public static Object getBean(String beanName){
        if(beanList.containsKey(beanName))
            return beanList.get(beanName);
        else {
            Object o = getContext().getBean(beanName);
            beanList.put(beanName, o);
            return o;
        }
    }

}

